package com.demon.mutehelper

import android.Manifest
import android.content.Intent
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity

class LoadingActivity : AppCompatActivity() {

  private val permissionsRequestLauncher =
    registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) {
      var permissionGrantedAll = true
      it.forEach { (s, b) -> permissionGrantedAll = permissionGrantedAll.and(b) }
        .takeIf { permissionGrantedAll }
        .run {
          startActivity(Intent(this@LoadingActivity, MainActivity::class.java))
          finish()
        }
    }

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    permissionsRequestLauncher.launch(
      arrayOf(
        Manifest.permission.ACCESS_FINE_LOCATION,
        Manifest.permission.ACCESS_COARSE_LOCATION,
        Manifest.permission.ACCESS_BACKGROUND_LOCATION,
      )
    )
  }
}